﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL.Util;

namespace MZ.UserControl.Money
{
    public partial class TopMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                var account = CacheHelper.GetAccount(Page.User.Identity.Name);
                UserInfo.InnerText = account.AccountName + "欢迎您再次到来 ^_^";

               

                foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
                {
                    if (node["module"] == "money")
                    {
                        var foo = from bar in node.ChildNodes.Cast<SiteMapNode>()
                                  select new
                                  {
                                      Title = bar.Title,
                                      Url = bar.Url,
                                      Class = SetCurrentNav(bar,SiteMap.CurrentNode)
                                  };
                        rptMenu.DataSource = foo;
                        rptMenu.DataBind();
                        break;
                    }
                }

                Page.Title = SiteMap.CurrentNode.Title;//设置标题
                
            }
        }
        /// <summary>
        /// 设置当前样式
        /// </summary>
        /// <param name="node">子模块一级连接</param>
        private string SetCurrentNav(SiteMapNode node,SiteMapNode currentNode)
        {
            string currentClass = "current";
            if (null==currentNode)
            {
                return string.Empty;
            }
            if (currentNode.Equals(node))
            {
                return currentClass;
            }
            return SetCurrentNav(node, currentNode.ParentNode);
        }
    }
}